#!/usr/bin/env python

import urllib
import sys
import os

def unquote(file):
    new_name = urllib.unquote(file)
    print("%s -> %s" % (file, new_name))
    os.rename(file, new_name)

def explore(dir):
    for root, dirs, files in os.walk(dir):
        for file in files:
            path = os.path.join(root, file)
            unquote(path)

def main():
    if (len(sys.argv) < 2):
        print "need files' name"
        exit()

    for item in sys.argv[1:] :
        if os.path.isfile(item):
            unquote(item)
        elif os.path.isdir(item):
            explore(item)

if __name__ == "__main__":
    main()
